#对于文件的一些操作
import datetime
import json

import login_info.login_info as login
def log_moudle(cont,mould):
    f = open("data_log/"+mould+".txt", "a+")
    f.write('\n____________________________________________________________\n')
    f.write('user: ' + login.emr_user + '\n')
    f.write('operate_time: ' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + '\n')
    f.write(cont + "\n")
    f.write('\n____________________________________________________________\n')
    f.close()
def wrong_table(cont):
    log_moudle(cont,'table_err')
def write_log(cont):
    log_moudle(cont,'success_sql')
def job_err(cont):
    log_moudle(cont,'job_err')
# def write_empty_fail(cont):
#     log_moudle(cont,'empty_fail')
# def write_empty_success(cont):
#     log_moudle(cont,'empty_success')


# 获取studio cookie
def get_cookies_from_txt():
    f = open("login_info/cookie.txt", "r")
    str = f.read()
    if(str==''):
        print('cookie.txt中没有内容')
    else:
        print('从文件中取得cookie:',str)
    return str
# 获取river cookie
def get_river_cookie():
    f = open("login_info/river_cookie.txt", "r")
    str = f.read()
    if(str==''):
        print('cookie.txt中没有内容')
    else:
        print('从文件中取得cookie:',str)
    return str
# 写入studio cookie
def put_cookies_in_txt(cookie):
    f = open("login_info/cookie.txt", "w")
    cookie = str(cookie)
    f.write(cookie)

#写入river_cookie
def put_river_cookie(cookie):
    f = open("login_info/river_cookie.txt", "w")
    cookie = str(cookie)
    f.write(cookie)

def put_json(dict):
    f = open("data_log/table_struct.json", "w")
    json.dump(dict,f)
    f.close()
def put_desc(dict):
    f = open("data_log/standard_config.json", "w")
    json.dump(dict,f)
    f.close()
def pub_cookies_in_json(dict):
    f = open("data_log/head.json", "w")
    json.dump(dict, f)
    f.close()
def get_table_desc():
    f = open("data_log/table_struct.json", "r")
    str = f.read()
    if(str==''):
        print('table_struct.json中没有内容')
    else:
        print('从文件中取得cookie:',str)
    f.close()
    return str
def get_stand_desc():
    f = open("data_log/standard_config.json", "r")
    str = f.read()
    if (str == ''):
        print('table_struct.json中没有内容')
    else:
        print('从文件中取得cookie:', str)
    f.close()
    return str

def get_head():
    f = open("data_log/head.json", "r")
    str = f.read()
    if(str==''):
        print('table_struct.json中没有内容')
    else:
        print('从文件中取得cookie:',str)
    f.close()
    return str
def wirte_empty_table(cont):
    f = open("data_log/empty_total.txt", "a+")
    f.write(cont + "\n")
    f.close()
def wirte_empty_fail(cont):
    f = open("data_log/empty_fail.txt", "a+")
    f.write(cont + "\n")
    f.close()
def wirte_empty_success(cont):
    f = open("data_log/empty_success.txt", "a+")
    f.write(cont + "\n")
    f.close()
def get_mission_from_txt():
    list_1 =[]
    f = open("data_log/mission.txt", "r")
    for line in f.readlines():
        line = line.strip('\n')
        list_1.append(line)
    return list_1

def get_mission_from_empty():
    list_1 =[]
    f = open("data_log/empty_total.txt", "r")
    for line in f.readlines():
        line = line.strip('\n')
        list_1.append(line)
    return list_1